package com.tomehay.termprojectmanage_server.service.impl;

import com.tomehay.termprojectmanage_server.enums.ResponseCode;
import com.tomehay.termprojectmanage_server.mapper.ClazzMapper;
import com.tomehay.termprojectmanage_server.pojo.Model.Clazz;
import com.tomehay.termprojectmanage_server.pojo.Model.CourseClazz;
import com.tomehay.termprojectmanage_server.mapper.CourseClazzMapper;
import com.tomehay.termprojectmanage_server.pojo.VO.ResultVO;
import com.tomehay.termprojectmanage_server.service.CourseClazzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tomehay
 * @since 2023-06-20
 */
@Service
public class CourseClazzServiceImpl extends ServiceImpl<CourseClazzMapper, CourseClazz> implements CourseClazzService {

    @Resource
    ClazzMapper clazzMapper;

    @Resource
    CourseClazzMapper courseClazzMapper;


    @Override
    public ResultVO<Void> AddClazzIntoCourse(int clazzId, int courseId) {
        CourseClazz courseClazz = new CourseClazz();
        courseClazz.setClazzId(clazzId);
        courseClazz.setCourseId(courseId);
        courseClazz.setCreateTime(LocalDateTime.now());
        courseClazzMapper.insert(courseClazz);
        return new ResultVO<>(ResponseCode.OK);
    }

    @Override
    public ResultVO<List<Clazz>> GetClazzByCourseId(int courseId) {
        List<Clazz> clazzes = clazzMapper.findClazzByCourseId(courseId);

        return new ResultVO<>(ResponseCode.auto(clazzes),clazzes);
    }

    @Override
    public ResultVO<Void> RemoveClazzFromCourse(int id) {
        courseClazzMapper.deleteById(id);
        return new ResultVO<>(ResponseCode.OK);
    }
}
